#pragma once
#include <iostream>
#include <string>
#include <unistd.h>

class Task
{
public:
    Task()
    {}

    Task(int x, int y, char op)
        :_x(x)
        ,_y(y)
        ,_op(op)
    {}

    void operator()()
    {
        switch(_op)
        {
            case '+':
            {
                _result = _x + _y;
                break;
            }
            case '-':
            {
                _result = _x - _y;
                break;
            }
            case '*':
            {
                _result = _x * _y;
                break;
            }
            case '/':
            {
                if(_y == 0)
                {
                    _exitCode = -1;
                }
                else{
                    _result = _x / _y;
                }
                break;
            }
            case '%':
            {
                if(_y == 0)
                {
                    _exitCode = -2;
                }
                else{
                    _result = _x % _y;
                }
                break;
            }
            default:
            {
                std::cout << "符号错误" << std::endl;
                break;
            }
        }
        usleep(100000);
    }

    std::string formatArg()
    {
        return std::to_string(_x) + _op + std::to_string(_y) + '=';
    }

    std::string formatRes()
    {
        return std::to_string(_result) + '[' + "exitCode : " + std::to_string(_exitCode) + ']';
    }

    ~Task()
    {}
private:
    int _x;
    int _y;      
    char _op;       // 运算符
    int _result;    // 结果
    int _exitCode;  // 退出码
};